package com.wty.design.creational.singleton;

import java.io.Serializable;

/**
 * @Author wangtengyu
 * @Create 2018-09-18-15:09
 */
public class HungrySingleton implements Serializable {

    private final static HungrySingleton instance=new HungrySingleton();

    public static HungrySingleton getInstance(){
        return instance;
    }

    private HungrySingleton(){
        if (instance!=null){
            throw new RuntimeException("单例构造器禁止反射");
        }
    }

    private Object readResolve(){
        return instance;
    }
}
